<script type="text/javascript">
    $(document).ready(function() {
        $('.add').live('click', function() {
            var random = Math.floor(Math.random()*100000);
            var token = hex_md5(random.toString());
            var form = '<tr style="display: none"><td><input type="text" name="name[]" /></td><td><input type="text" name="amount[]" /></td><td class="hidden"><input type="hidden" name="token[]" value="' + token + '"/></td><td><a class="block add" href="#"><img alt="" src="<?php echo base_url(); ?>assets/img/plus.png"></img></a></td><td><a class="block remove" href="#"><img alt="" src="<?php echo base_url(); ?>assets/img/delete.png"></img></a></td></tr>'
                    
            $(form).insertAfter($(this).parent().parent());
            
            $("tr:hidden").show('slow');
            
            return false;
        });
        
        $('.remove').live('click', function() {
            var element = $(this).parent().parent();
            
            element.hide(function() {
                element.remove();
            });
            
            return false;
        });
    });
</script>
<form name="add" action="<?php echo site_url("expenses/add"); ?>" method="post">
    <table id="items" cellspacing="0">
        <tbody>
            <tr>
                <th>Name</th>
                <th>Amount</th>
            </tr>
            <tr>
                <td><input type="text" name="name[]" /></td>
                <td><input type="text" name="amount[]" /></td>
                <td class="hidden"><input type="hidden" name="token[]" value="<?php echo $token; ?>"/></td>
                <td><a class="block add" href="#"><img alt="" src="<?php echo base_url(); ?>assets/img/plus.png"></img></a></td>
            </tr>
        </tbody>
    </table>
    <input type="submit" name="submit" value="Save" />
</form>
<div id="summary">
    <h2>Summary</h2>
    <p>Today's Expenses: Rp <?php echo $today; ?></p>
    <p>Total: Rp <?php echo $total; ?></p>
</div>